package com.gdut.huayan.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gdut.huayan.utils.StringUtils;
import com.gdut.huayan.validation.NumRange;
import com.gdut.huayan.validation.group.GroupAdd;
import com.gdut.huayan.validation.group.GroupUpdate;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;


@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_tablet")
public class Tablet implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    @Null(groups = {GroupAdd.class})
    @NotNull(groups = {GroupUpdate.class})
    private Long id;

    /**
     * 数据填写错误，若已支付请联系管理员
     * 用户id
     */
    private Long userId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 1-往生，2-延生
     */
    @NumRange(min = 1, max = 2, message = "牌位类型错误")
    private Integer tabletType;

    /**
     * 往生牌位类型:1-历代，2-先人，3-法界，4-地基
     */
    @NumRange(min = 1, max = 4, message = "往生牌位类型错误")
    private Integer lastTabletType;

    /**
     * 1-大，2-中，3-小
     */
    @NumRange(min = 1, max = 3, message = "牌位大小类型错误")
    private Integer sizeType;

    /**
     * 1-个人，2-企业
     */
    @NumRange(min = 1, max = 2, message = "printType类型错误")
    private Integer printType;

    /**
     * 1-保存，2-不保存
     */
    private Integer isSave;

    /**
     * 祖先姓氏
     */
    private String ancestralSurname;

    /**
     * 地基主地址
     */
    private String foundationAddress;

    /**
     * 文疏地址
     */
    private String paperAddress;

    /**
     * 联系人
     */
    @NotBlank(message = "联系人姓名不能为空")
    private String contactName;

    /**
     * 联系电话
     */
    @NotBlank(message = "联系人电话不能为空")
    private String contactPhone;

    /**
     * 是否打印
     */
    private Integer printStatus;

    @TableField(exist = false)
    private String number;

    public String getTabletNumber() {
        if (this.number == null) {
            if (this.id == null) {
                return null;
            } else {
                this.number = StringUtils.beDigits(Long.toString(this.id,36)).toUpperCase();
            }
        }
        return getNumber();
    }

}
